package core;

import java.util.LinkedList;
import java.util.List;

public class Player {
	private String name;
	private int money;
	private Dice dice;
	private List<Item> items;
	private int[] groups = new int[10];

	public Player(String n, int m) {
		name = new String(n);
		money = m;
		dice = new Dice();
		items = new LinkedList<Item>();

		for (int i = 0; i < 10; ++i)
			groups[i] = 0;
	}

	public boolean buyItem(Item i) {
		if (i.getPrice() > money)
			return false;
		if (i.sell(this)) {
			this.addItem(i);
			pay(i.getPrice());
			System.out.println(i.getPrice());
			return true;
		}
		return false;
	}

	public void throwDice() {
		dice.throwDice();
	}

	public void addItem(Item i) {
		items.add(i);
		groups[i.getGroup()]++;
	}

	public void removeItem(Item i) {
		items.remove(i);
		groups[i.getGroup()]--;
	}

	public boolean pay(int m) {
		if (m > money)
			return false;
		money -= m;
		return true;
	}

	public void receive(int m) {
		money += m;
	}

	public int getThrownValue() {
		return dice.getValue();
	}

	public int getNrOfItemsOwnedFromGroup(int g) {
		return groups[g];
	}

	public String getName() {
		return name;
	}

	public void setName(String n) {
		name = n;
	}

	public boolean isDoubleThrow() {
		if (dice.getX() == dice.getY())
			return true;
		return false;
	}

	public int getMoney() {
		return money;
	}
}
